﻿using System;
using System.Web.Mvc;
using System.ComponentModel.DataAnnotations;
using MvcTemplates.Model;

namespace MvcTemplates.Client.Models
{
    public class ViewModel
    {
        [HtmlAttributes( new[] {"class"}, new[] {"random_class"} )]   
        [HelpMessage("You can completely customize html attributes by using the HtmlAttributes Attribute",
            HtmlAttributeNames = new[]{"id"}, HtmlAttributeValues = new[]{"TextBox_helpMesssageId"})]
        public string TextBox { get; set; }

        [HiddenInput]
        public string HiddenInputWithReadonlyDisplay { get; set; }

        [HiddenInput(DisplayValue = false)]
        public string HiddenInput { get; set; }

        [DoNotRender]        
        public string IgnoreThisField { get; set; }

        [DisplayTemplate]
        public string DisplayForNoInput { get; set; }

        public decimal Decimal { get; set; }
        
        [DisplayFormat(DataFormatString = "{0:c}", ApplyFormatInEditMode = true)]
        public decimal DecimalFormattedAsMoney { get; set; }

        public bool CheckBox { get; set; }

        [Label( RenderAfterField = true, PutInFieldContainer = true, Text = "Check box with Label Rendered after the Field" )]
        public bool CheckBoxWithLabelOnRight { get; set; }

        [LabelAfterField("two labels")]
        [HelpMessage("This checkbox shows that you can have an additional label if you use the LabelAfterField Attribute")]
        public bool AnotherCheckBox { get; set; }

        public CheckBoxList CheckBoxList { get; set; }    

        public RadioButtonList RadioButtonList { get; set; }

        [DropDown("SelectListItemsViewDataKey")]
        public string DropDownOptionsFromViewData { get; set; }

        public DropDown DropDown { get; set; }

        public ViewModel AnotherViewModel { get; set; }

        [HelpMessage("A static Help Message")]
        [Display(Prompt = "watermark here")]
        public string HelpMessage { get; set; }

        public DateTime Datetime { get; set; }
        
        [DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}", ApplyFormatInEditMode = true)]
        public DateTime DatetimeFormatted { get; set; }

        [AutoComplete( "Autocomplete", "Home", Delay = 0)]
        [HelpMessage("Start typing the word Link")]
        public string AutoComplete { get; set; }

        [FieldContainer(typeof(FieldsetTagBuilder))]
        [Label(DoNotRender = true)]
        [HelpMessage("You can control field and label containers by using the FieldContainer or LabelContainer Attribute")]
        public string TextBoxWithCustomFieldContainer { get; set; }

        public ViewModel()
        {
            TextBox = "hi i'm a text box with a random_class css class added";
            HiddenInputWithReadonlyDisplay = "I'm a hidden input with a readonly display";
            HiddenInput = "i'm hidden so you probably don't see this";
            DisplayForNoInput = "I called Html.DisplayFor() instead of EditorFor";
            Decimal = 10.00m;
            DecimalFormattedAsMoney = 50.00m;
            
            DropDown = new DropDown
                           {
                               Value = "using a model",
                               Options = new SelectList( new[] {"thing3", "thing4", "using a model"}, "using a model" )
                           };
            
            CheckBoxList = new CheckBoxList
                               {
                                   SelectedOptions = new[]{ "thing3", "thing4" },
                                   Options = new SelectList( new[]{ "thing1", "thing2", "thing3", "thing4" } )
                               };

            RadioButtonList = new RadioButtonList
                                  {
                                      Value = "using a model",
                                      Options = new SelectList( new[] {"thing3", "thing4", "using a model"}, "using a model" )
                                  };

            Datetime = DatetimeFormatted = DateTime.Now;
        }
    }

    public class FieldsetTagBuilder : TagBuilder
    {
        public FieldsetTagBuilder() : base( "fieldset" )
        {
            var legend = new TagBuilder( "legend" );
            legend.SetInnerText( "Text Box with Custom Field Container!" );
            legend.Attributes.Add( "style", "padding-top:20px;" );
            this.InnerHtml = legend.ToString();
        }
    }
}